package cn.skyquant.quant4j.service.boot.web.controller;

import cn.skyquant.quant4j.api.dto.ResultDTO;
import cn.skyquant.quant4j.service.boot.model.authority.RoleAuthority;
import cn.skyquant.quant4j.service.boot.model.system.ServiceSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system")
@RoleAuthority(roleNames = {RoleAuthority.administrator})
public class SystemController {

    @Autowired
    ServiceSystemService systemService;


    @RequestMapping(value = "/info",method = RequestMethod.GET)
    @ResponseBody
    public ResultDTO<Map> info(WebRequest webRequest, HttpServletRequest request, HttpServletResponse response){
        Map map = new HashMap<>();
        map.put("remote_ip", request.getHeader("X-Real-IP"));
        List<Map> list = systemService.all();
        map.put("list", list);
        return ResultDTO.success(map);
    }
}
